package springboot.bigdata.demo.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import springboot.bigdata.demo.model.User;
import springboot.bigdata.demo.service.UserService;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/user")
@Slf4j
@Api(description = "用户controller")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation("按照id获取用户信息")
    @ResponseBody
    @PostMapping ("/getUserList")
    public Map getUserList(User userPar) {

        PageInfo<User> pageInfo = userService.getUserList(userPar);

        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("total", pageInfo.getTotal());
        resultMap.put("rows", pageInfo.getList());

        return resultMap;
    }

    @GetMapping("/toUserList")
    public String toUserList() {

        return "user/index";
    }
}
